package org.linlinjava.litemall.db.domain;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;

public class LitemallShopCheckItem {
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    private Integer id;

    private Integer shopCheckId;

    private Integer shopMerchandiseId;

    private Integer systemSurplusNumber;

    private Double checkNumber;

    private Integer lossNumber;

    private String remark;

    private Boolean deleted;

    private LocalDateTime addTime;

    private Integer addUserId;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getShopCheckId() {
        return shopCheckId;
    }

    public void setShopCheckId(Integer shopCheckId) {
        this.shopCheckId = shopCheckId;
    }

    public Integer getShopMerchandiseId() {
        return shopMerchandiseId;
    }

    public void setShopMerchandiseId(Integer shopMerchandiseId) {
        this.shopMerchandiseId = shopMerchandiseId;
    }

    public Integer getSystemSurplusNumber() {
        return systemSurplusNumber;
    }

    public void setSystemSurplusNumber(Integer systemSurplusNumber) {
        this.systemSurplusNumber = systemSurplusNumber;
    }

    public Double getCheckNumber() {
        return checkNumber;
    }

    public void setCheckNumber(Double checkNumber) {
        this.checkNumber = checkNumber;
    }

    public Integer getLossNumber() {
        return lossNumber;
    }

    public void setLossNumber(Integer lossNumber) {
        this.lossNumber = lossNumber;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public void andLogicalDeleted(boolean deleted) {
        setDeleted(deleted ? Deleted.IS_DELETED.value() : Deleted.NOT_DELETED.value());
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public LocalDateTime getAddTime() {
        return addTime;
    }

    public void setAddTime(LocalDateTime addTime) {
        this.addTime = addTime;
    }

    public Integer getAddUserId() {
        return addUserId;
    }

    public void setAddUserId(Integer addUserId) {
        this.addUserId = addUserId;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", IS_DELETED=").append(IS_DELETED);
        sb.append(", NOT_DELETED=").append(NOT_DELETED);
        sb.append(", id=").append(id);
        sb.append(", shopCheckId=").append(shopCheckId);
        sb.append(", shopMerchandiseId=").append(shopMerchandiseId);
        sb.append(", systemSurplusNumber=").append(systemSurplusNumber);
        sb.append(", checkNumber=").append(checkNumber);
        sb.append(", lossNumber=").append(lossNumber);
        sb.append(", remark=").append(remark);
        sb.append(", deleted=").append(deleted);
        sb.append(", addTime=").append(addTime);
        sb.append(", addUserId=").append(addUserId);
        sb.append("]");
        return sb.toString();
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        LitemallShopCheckItem other = (LitemallShopCheckItem) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getShopCheckId() == null ? other.getShopCheckId() == null : this.getShopCheckId().equals(other.getShopCheckId()))
            && (this.getShopMerchandiseId() == null ? other.getShopMerchandiseId() == null : this.getShopMerchandiseId().equals(other.getShopMerchandiseId()))
            && (this.getSystemSurplusNumber() == null ? other.getSystemSurplusNumber() == null : this.getSystemSurplusNumber().equals(other.getSystemSurplusNumber()))
            && (this.getCheckNumber() == null ? other.getCheckNumber() == null : this.getCheckNumber().equals(other.getCheckNumber()))
            && (this.getLossNumber() == null ? other.getLossNumber() == null : this.getLossNumber().equals(other.getLossNumber()))
            && (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()))
            && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
            && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
            && (this.getAddUserId() == null ? other.getAddUserId() == null : this.getAddUserId().equals(other.getAddUserId()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getShopCheckId() == null) ? 0 : getShopCheckId().hashCode());
        result = prime * result + ((getShopMerchandiseId() == null) ? 0 : getShopMerchandiseId().hashCode());
        result = prime * result + ((getSystemSurplusNumber() == null) ? 0 : getSystemSurplusNumber().hashCode());
        result = prime * result + ((getCheckNumber() == null) ? 0 : getCheckNumber().hashCode());
        result = prime * result + ((getLossNumber() == null) ? 0 : getLossNumber().hashCode());
        result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
        result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
        result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
        result = prime * result + ((getAddUserId() == null) ? 0 : getAddUserId().hashCode());
        return result;
    }

    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        shopCheckId("shop_check_id", "shopCheckId", "INTEGER", false),
        shopMerchandiseId("shop_merchandise_id", "shopMerchandiseId", "INTEGER", false),
        systemSurplusNumber("system_surplus_number", "systemSurplusNumber", "INTEGER", false),
        checkNumber("check_number", "checkNumber", "INTEGER", false),
        lossNumber("loss_number", "lossNumber", "INTEGER", false),
        remark("remark", "remark", "VARCHAR", false),
        deleted("deleted", "deleted", "BIT", false),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        addUserId("add_user_id", "addUserId", "INTEGER", false);

        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}